{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import keras as ks\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Dense, Activation, Embedding, LSTM\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from keras.wrappers.scikit_learn import KerasClassifier\n",
    "from sklearn.pipeline import Pipeline\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Dense\n",
    "from keras.wrappers.scikit_learn import KerasClassifier\n",
    "from sklearn.model_selection import cross_val_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "x=['HR', 'O2Sat', 'Temp', 'SBP', 'MAP', 'DBP', 'Resp', 'EtCO2',\n",
    "       'BaseExcess', 'HCO3', 'FiO2', 'pH', 'PaCO2', 'SaO2', 'AST', 'BUN',\n",
    "       'Alkalinephos', 'Calcium', 'Chloride', 'Creatinine', 'Bilirubin_direct',\n",
    "       'Glucose', 'Lactate', 'Magnesium', 'Phosphate', 'Potassium',\n",
    "       'Bilirubin_total', 'TroponinI', 'Hct', 'Hgb', 'PTT', 'WBC',\n",
    "       'Fibrinogen', 'Platelets', 'Age', 'Gender', 'Unit1', 'Unit2',\n",
    "       'HospAdmTime', 'ICULOS']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    " def create_model():\n",
    "        model = Sequential()\n",
    "        model.add(Dense(40, input_dim=40, activation='relu'))\n",
    "        \n",
    "        model.add(Dense(1, activation='sigmoid'))\n",
    "        model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n",
    "        return model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "estimators = []\n",
    "estimators.append(('standardize', StandardScaler()))\n",
    "estimators.append(('mlp', KerasClassifier(build_fn=create_larger, epochs=1, batch_size=5, verbose=0)))\n",
    "pipeline = Pipeline(estimators)\n",
    "kfold = StratifiedKFold(n_splits=10, shuffle=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "data=pd.read_csv('./SetA/setA.csv')\n",
    "data=data.fillna(0)\n",
    "X=data[x].copy()\n",
    "y=data['SepsisLabel'].copy()\n",
    "x_train,x_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "model=create_model()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3104"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3104"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       0\n",
       "1       0\n",
       "2       0\n",
       "3       0\n",
       "4       0\n",
       "       ..\n",
       "3099    0\n",
       "3100    0\n",
       "3101    0\n",
       "3102    0\n",
       "3103    0\n",
       "Name: SepsisLabel, Length: 3104, dtype: int64"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "498     1\n",
       "499     1\n",
       "500     1\n",
       "501     1\n",
       "502     1\n",
       "       ..\n",
       "2423    1\n",
       "2424    1\n",
       "2425    1\n",
       "2426    1\n",
       "2427    1\n",
       "Name: SepsisLabel, Length: 117, dtype: int64"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y[y==1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train,x_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/200\n",
      "2483/2483 [==============================] - 0s 191us/step - loss: 1.3938 - accuracy: 0.9203\n",
      "Epoch 2/200\n",
      "2483/2483 [==============================] - 0s 16us/step - loss: 0.8067 - accuracy: 0.9303\n",
      "Epoch 3/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.5067 - accuracy: 0.9472\n",
      "Epoch 4/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.3653 - accuracy: 0.9464\n",
      "Epoch 5/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.2845 - accuracy: 0.9549\n",
      "Epoch 6/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.2442 - accuracy: 0.9585\n",
      "Epoch 7/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.2136 - accuracy: 0.9625\n",
      "Epoch 8/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.2319 - accuracy: 0.9549\n",
      "Epoch 9/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.2023 - accuracy: 0.9605\n",
      "Epoch 10/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.1852 - accuracy: 0.9621\n",
      "Epoch 11/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.1657 - accuracy: 0.9654\n",
      "Epoch 12/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.1543 - accuracy: 0.9666\n",
      "Epoch 13/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.1514 - accuracy: 0.9682\n",
      "Epoch 14/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.1437 - accuracy: 0.9686\n",
      "Epoch 15/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.1325 - accuracy: 0.9690\n",
      "Epoch 16/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.1303 - accuracy: 0.9698\n",
      "Epoch 17/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.1362 - accuracy: 0.9726\n",
      "Epoch 18/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.1327 - accuracy: 0.9678\n",
      "Epoch 19/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.1441 - accuracy: 0.9686\n",
      "Epoch 20/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.1231 - accuracy: 0.9694\n",
      "Epoch 21/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.1151 - accuracy: 0.9726\n",
      "Epoch 22/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.1109 - accuracy: 0.9690\n",
      "Epoch 23/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.1031 - accuracy: 0.9722\n",
      "Epoch 24/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.1129 - accuracy: 0.9682\n",
      "Epoch 25/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.1044 - accuracy: 0.9738\n",
      "Epoch 26/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0986 - accuracy: 0.9742\n",
      "Epoch 27/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.1069 - accuracy: 0.9714\n",
      "Epoch 28/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.0924 - accuracy: 0.9754\n",
      "Epoch 29/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0898 - accuracy: 0.9730\n",
      "Epoch 30/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0864 - accuracy: 0.9742\n",
      "Epoch 31/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.1020 - accuracy: 0.9710\n",
      "Epoch 32/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.1080 - accuracy: 0.9722\n",
      "Epoch 33/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0963 - accuracy: 0.9734\n",
      "Epoch 34/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0845 - accuracy: 0.9758\n",
      "Epoch 35/200\n",
      "2483/2483 [==============================] - 0s 27us/step - loss: 0.0821 - accuracy: 0.9762\n",
      "Epoch 36/200\n",
      "2483/2483 [==============================] - 0s 33us/step - loss: 0.0819 - accuracy: 0.9734\n",
      "Epoch 37/200\n",
      "2483/2483 [==============================] - 0s 37us/step - loss: 0.0944 - accuracy: 0.9770\n",
      "Epoch 38/200\n",
      "2483/2483 [==============================] - 0s 29us/step - loss: 0.0769 - accuracy: 0.9770\n",
      "Epoch 39/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0744 - accuracy: 0.9766\n",
      "Epoch 40/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0740 - accuracy: 0.9783\n",
      "Epoch 41/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0772 - accuracy: 0.9758\n",
      "Epoch 42/200\n",
      "2483/2483 [==============================] - 0s 24us/step - loss: 0.0825 - accuracy: 0.9746\n",
      "Epoch 43/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0787 - accuracy: 0.9766\n",
      "Epoch 44/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.0710 - accuracy: 0.9758\n",
      "Epoch 45/200\n",
      "2483/2483 [==============================] - 0s 53us/step - loss: 0.0681 - accuracy: 0.9787\n",
      "Epoch 46/200\n",
      "2483/2483 [==============================] - 0s 29us/step - loss: 0.0775 - accuracy: 0.9754\n",
      "Epoch 47/200\n",
      "2483/2483 [==============================] - 0s 29us/step - loss: 0.0723 - accuracy: 0.9758\n",
      "Epoch 48/200\n",
      "2483/2483 [==============================] - 0s 26us/step - loss: 0.0703 - accuracy: 0.9762\n",
      "Epoch 49/200\n",
      "2483/2483 [==============================] - 0s 27us/step - loss: 0.0656 - accuracy: 0.9791\n",
      "Epoch 50/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0721 - accuracy: 0.9770\n",
      "Epoch 51/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0671 - accuracy: 0.9799\n",
      "Epoch 52/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0649 - accuracy: 0.9778\n",
      "Epoch 53/200\n",
      "2483/2483 [==============================] - 0s 27us/step - loss: 0.0673 - accuracy: 0.9778\n",
      "Epoch 54/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0721 - accuracy: 0.9766\n",
      "Epoch 55/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0667 - accuracy: 0.9774\n",
      "Epoch 56/200\n",
      "2483/2483 [==============================] - 0s 38us/step - loss: 0.0726 - accuracy: 0.9774\n",
      "Epoch 57/200\n",
      "2483/2483 [==============================] - 0s 31us/step - loss: 0.0781 - accuracy: 0.9762\n",
      "Epoch 58/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0663 - accuracy: 0.9770\n",
      "Epoch 59/200\n",
      "2483/2483 [==============================] - 0s 27us/step - loss: 0.0693 - accuracy: 0.9746\n",
      "Epoch 60/200\n",
      "2483/2483 [==============================] - 0s 25us/step - loss: 0.0733 - accuracy: 0.9758\n",
      "Epoch 61/200\n",
      "2483/2483 [==============================] - 0s 35us/step - loss: 0.0590 - accuracy: 0.9819\n",
      "Epoch 62/200\n",
      "2483/2483 [==============================] - 0s 24us/step - loss: 0.0579 - accuracy: 0.9791\n",
      "Epoch 63/200\n",
      "2483/2483 [==============================] - 0s 26us/step - loss: 0.0573 - accuracy: 0.9791\n",
      "Epoch 64/200\n",
      "2483/2483 [==============================] - 0s 25us/step - loss: 0.0614 - accuracy: 0.9795\n",
      "Epoch 65/200\n",
      "2483/2483 [==============================] - 0s 25us/step - loss: 0.0690 - accuracy: 0.9795\n",
      "Epoch 66/200\n",
      "2483/2483 [==============================] - 0s 23us/step - loss: 0.0575 - accuracy: 0.9783\n",
      "Epoch 67/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0558 - accuracy: 0.9791\n",
      "Epoch 68/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0539 - accuracy: 0.9815\n",
      "Epoch 69/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0562 - accuracy: 0.9807\n",
      "Epoch 70/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.0603 - accuracy: 0.9795\n",
      "Epoch 71/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.0591 - accuracy: 0.9787\n",
      "Epoch 72/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0561 - accuracy: 0.9795\n",
      "Epoch 73/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0537 - accuracy: 0.9823\n",
      "Epoch 74/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.0562 - accuracy: 0.9819\n",
      "Epoch 75/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0601 - accuracy: 0.9795\n",
      "Epoch 76/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0576 - accuracy: 0.9791\n",
      "Epoch 77/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0540 - accuracy: 0.9807\n",
      "Epoch 78/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0600 - accuracy: 0.9803\n",
      "Epoch 79/200\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0838 - accuracy: 0.9758\n",
      "Epoch 80/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0636 - accuracy: 0.9774\n",
      "Epoch 81/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0551 - accuracy: 0.9831\n",
      "Epoch 82/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0599 - accuracy: 0.9774\n",
      "Epoch 83/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0551 - accuracy: 0.9791\n",
      "Epoch 84/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0628 - accuracy: 0.9783\n",
      "Epoch 85/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0668 - accuracy: 0.9778\n",
      "Epoch 86/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0568 - accuracy: 0.9791\n",
      "Epoch 87/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0563 - accuracy: 0.9807\n",
      "Epoch 88/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0501 - accuracy: 0.9811\n",
      "Epoch 89/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0510 - accuracy: 0.9803\n",
      "Epoch 90/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0520 - accuracy: 0.9803\n",
      "Epoch 91/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0555 - accuracy: 0.9819\n",
      "Epoch 92/200\n",
      "2483/2483 [==============================] - 0s 16us/step - loss: 0.0499 - accuracy: 0.9823\n",
      "Epoch 93/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0542 - accuracy: 0.9774\n",
      "Epoch 94/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0528 - accuracy: 0.9803\n",
      "Epoch 95/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0479 - accuracy: 0.9835\n",
      "Epoch 96/200\n",
      "2483/2483 [==============================] - 0s 26us/step - loss: 0.0465 - accuracy: 0.9843\n",
      "Epoch 97/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0484 - accuracy: 0.9807\n",
      "Epoch 98/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0479 - accuracy: 0.9827\n",
      "Epoch 99/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.0465 - accuracy: 0.9855\n",
      "Epoch 100/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0461 - accuracy: 0.9843\n",
      "Epoch 101/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.0489 - accuracy: 0.9811\n",
      "Epoch 102/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0510 - accuracy: 0.9807\n",
      "Epoch 103/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0456 - accuracy: 0.9843\n",
      "Epoch 104/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0460 - accuracy: 0.9843\n",
      "Epoch 105/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0492 - accuracy: 0.9831\n",
      "Epoch 106/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0485 - accuracy: 0.9827\n",
      "Epoch 107/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0479 - accuracy: 0.9819\n",
      "Epoch 108/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0447 - accuracy: 0.9831\n",
      "Epoch 109/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0527 - accuracy: 0.9811\n",
      "Epoch 110/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0480 - accuracy: 0.9811\n",
      "Epoch 111/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0475 - accuracy: 0.9827\n",
      "Epoch 112/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0576 - accuracy: 0.9803\n",
      "Epoch 113/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0550 - accuracy: 0.9787\n",
      "Epoch 114/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0538 - accuracy: 0.9807\n",
      "Epoch 115/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0493 - accuracy: 0.9823\n",
      "Epoch 116/200\n",
      "2483/2483 [==============================] - 0s 18us/step - loss: 0.0546 - accuracy: 0.9807\n",
      "Epoch 117/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0485 - accuracy: 0.9811\n",
      "Epoch 118/200\n",
      "2483/2483 [==============================] - 0s 24us/step - loss: 0.0481 - accuracy: 0.9815\n",
      "Epoch 119/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0441 - accuracy: 0.9843\n",
      "Epoch 120/200\n",
      "2483/2483 [==============================] - 0s 17us/step - loss: 0.0466 - accuracy: 0.9823\n",
      "Epoch 121/200\n",
      "2483/2483 [==============================] - 0s 24us/step - loss: 0.0448 - accuracy: 0.9827\n",
      "Epoch 122/200\n",
      "2483/2483 [==============================] - 0s 27us/step - loss: 0.0481 - accuracy: 0.9835\n",
      "Epoch 123/200\n",
      "2483/2483 [==============================] - 0s 24us/step - loss: 0.0447 - accuracy: 0.9847\n",
      "Epoch 124/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0493 - accuracy: 0.9811\n",
      "Epoch 125/200\n",
      "2483/2483 [==============================] - 0s 25us/step - loss: 0.0429 - accuracy: 0.9835\n",
      "Epoch 126/200\n",
      "2483/2483 [==============================] - 0s 27us/step - loss: 0.0430 - accuracy: 0.9827\n",
      "Epoch 127/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0437 - accuracy: 0.9851\n",
      "Epoch 128/200\n",
      "2483/2483 [==============================] - 0s 34us/step - loss: 0.0419 - accuracy: 0.9863\n",
      "Epoch 129/200\n",
      "2483/2483 [==============================] - 0s 28us/step - loss: 0.0460 - accuracy: 0.9807\n",
      "Epoch 130/200\n",
      "2483/2483 [==============================] - 0s 25us/step - loss: 0.0449 - accuracy: 0.9847\n",
      "Epoch 131/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0410 - accuracy: 0.9847\n",
      "Epoch 132/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0448 - accuracy: 0.9843\n",
      "Epoch 133/200\n",
      "2483/2483 [==============================] - 0s 29us/step - loss: 0.0425 - accuracy: 0.9859\n",
      "Epoch 134/200\n",
      "2483/2483 [==============================] - 0s 23us/step - loss: 0.0411 - accuracy: 0.9851\n",
      "Epoch 135/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0463 - accuracy: 0.9823\n",
      "Epoch 136/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0545 - accuracy: 0.9851\n",
      "Epoch 137/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0410 - accuracy: 0.9835\n",
      "Epoch 138/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0468 - accuracy: 0.9847\n",
      "Epoch 139/200\n",
      "2483/2483 [==============================] - 0s 28us/step - loss: 0.0469 - accuracy: 0.9815\n",
      "Epoch 140/200\n",
      "2483/2483 [==============================] - 0s 28us/step - loss: 0.0618 - accuracy: 0.9795\n",
      "Epoch 141/200\n",
      "2483/2483 [==============================] - 0s 24us/step - loss: 0.0715 - accuracy: 0.9787\n",
      "Epoch 142/200\n",
      "2483/2483 [==============================] - 0s 25us/step - loss: 0.0495 - accuracy: 0.9827\n",
      "Epoch 143/200\n",
      "2483/2483 [==============================] - 0s 24us/step - loss: 0.0505 - accuracy: 0.9831\n",
      "Epoch 144/200\n",
      "2483/2483 [==============================] - 0s 26us/step - loss: 0.0588 - accuracy: 0.9783\n",
      "Epoch 145/200\n",
      "2483/2483 [==============================] - 0s 28us/step - loss: 0.0658 - accuracy: 0.9783\n",
      "Epoch 146/200\n",
      "2483/2483 [==============================] - 0s 32us/step - loss: 0.0477 - accuracy: 0.9811\n",
      "Epoch 147/200\n",
      "2483/2483 [==============================] - 0s 27us/step - loss: 0.0544 - accuracy: 0.9827\n",
      "Epoch 148/200\n",
      "2483/2483 [==============================] - 0s 27us/step - loss: 0.0529 - accuracy: 0.9815\n",
      "Epoch 149/200\n",
      "2483/2483 [==============================] - 0s 23us/step - loss: 0.0422 - accuracy: 0.9831\n",
      "Epoch 150/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0423 - accuracy: 0.9863\n",
      "Epoch 151/200\n",
      "2483/2483 [==============================] - 0s 31us/step - loss: 0.0414 - accuracy: 0.9831\n",
      "Epoch 152/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0428 - accuracy: 0.9839\n",
      "Epoch 153/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0379 - accuracy: 0.9855\n",
      "Epoch 154/200\n",
      "2483/2483 [==============================] - 0s 28us/step - loss: 0.0394 - accuracy: 0.9863\n",
      "Epoch 155/200\n",
      "2483/2483 [==============================] - 0s 31us/step - loss: 0.0377 - accuracy: 0.9867\n",
      "Epoch 156/200\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0448 - accuracy: 0.9831\n",
      "Epoch 157/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0413 - accuracy: 0.9855\n",
      "Epoch 158/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0464 - accuracy: 0.9851\n",
      "Epoch 159/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0394 - accuracy: 0.9851\n",
      "Epoch 160/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0379 - accuracy: 0.9859\n",
      "Epoch 161/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0378 - accuracy: 0.9859\n",
      "Epoch 162/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0453 - accuracy: 0.9843\n",
      "Epoch 163/200\n",
      "2483/2483 [==============================] - ETA: 0s - loss: 0.0494 - accuracy: 0.97 - 0s 20us/step - loss: 0.0471 - accuracy: 0.9839\n",
      "Epoch 164/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0440 - accuracy: 0.9847\n",
      "Epoch 165/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0487 - accuracy: 0.9823\n",
      "Epoch 166/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0421 - accuracy: 0.9855\n",
      "Epoch 167/200\n",
      "2483/2483 [==============================] - 0s 27us/step - loss: 0.0377 - accuracy: 0.9875\n",
      "Epoch 168/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0442 - accuracy: 0.9863\n",
      "Epoch 169/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0426 - accuracy: 0.9847\n",
      "Epoch 170/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0389 - accuracy: 0.9847\n",
      "Epoch 171/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0528 - accuracy: 0.9811\n",
      "Epoch 172/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0424 - accuracy: 0.9855\n",
      "Epoch 173/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0381 - accuracy: 0.9867\n",
      "Epoch 174/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0377 - accuracy: 0.9871\n",
      "Epoch 175/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0406 - accuracy: 0.9843\n",
      "Epoch 176/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0412 - accuracy: 0.9855\n",
      "Epoch 177/200\n",
      "2483/2483 [==============================] - 0s 24us/step - loss: 0.0425 - accuracy: 0.9839\n",
      "Epoch 178/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0368 - accuracy: 0.9887\n",
      "Epoch 179/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0359 - accuracy: 0.9875\n",
      "Epoch 180/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0377 - accuracy: 0.9871\n",
      "Epoch 181/200\n",
      "2483/2483 [==============================] - 0s 19us/step - loss: 0.0442 - accuracy: 0.9823\n",
      "Epoch 182/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0369 - accuracy: 0.9879\n",
      "Epoch 183/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0428 - accuracy: 0.9835\n",
      "Epoch 184/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0369 - accuracy: 0.9871\n",
      "Epoch 185/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0517 - accuracy: 0.9803\n",
      "Epoch 186/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0405 - accuracy: 0.9855\n",
      "Epoch 187/200\n",
      "2483/2483 [==============================] - 0s 25us/step - loss: 0.0435 - accuracy: 0.9815\n",
      "Epoch 188/200\n",
      "2483/2483 [==============================] - 0s 23us/step - loss: 0.0440 - accuracy: 0.9831\n",
      "Epoch 189/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0360 - accuracy: 0.9875\n",
      "Epoch 190/200\n",
      "2483/2483 [==============================] - 0s 20us/step - loss: 0.0372 - accuracy: 0.9867\n",
      "Epoch 191/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0365 - accuracy: 0.9875\n",
      "Epoch 192/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0367 - accuracy: 0.9879\n",
      "Epoch 193/200\n",
      "2483/2483 [==============================] - ETA: 0s - loss: 0.0375 - accuracy: 0.98 - 0s 25us/step - loss: 0.0369 - accuracy: 0.9863\n",
      "Epoch 194/200\n",
      "2483/2483 [==============================] - 0s 26us/step - loss: 0.0357 - accuracy: 0.9875\n",
      "Epoch 195/200\n",
      "2483/2483 [==============================] - 0s 26us/step - loss: 0.0424 - accuracy: 0.9851\n",
      "Epoch 196/200\n",
      "2483/2483 [==============================] - 0s 26us/step - loss: 0.0398 - accuracy: 0.9863\n",
      "Epoch 197/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0365 - accuracy: 0.9867\n",
      "Epoch 198/200\n",
      "2483/2483 [==============================] - 0s 23us/step - loss: 0.0369 - accuracy: 0.9875\n",
      "Epoch 199/200\n",
      "2483/2483 [==============================] - 0s 22us/step - loss: 0.0468 - accuracy: 0.9839\n",
      "Epoch 200/200\n",
      "2483/2483 [==============================] - 0s 21us/step - loss: 0.0427 - accuracy: 0.9851\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.callbacks.History at 0x27f095d9288>"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.fit(x_train, y_train,epochs=200,batch_size=128)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "621/621 [==============================] - 0s 18us/step\n"
     ]
    }
   ],
   "source": [
    "score = model.evaluate(x_test, y_test, batch_size=128)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2.9582185261491416, 0.9500805139541626]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_pred=model.predict(x_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(y_pred[y_pred==1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(y_test[y_test==1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
